package com.zhongxi.guoyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.projectItem.ProjectItemData;

import java.util.List;

/**
 * Created by Administrator on 2016/12/10.
 */

public class GvShopSlidingAdapter extends BaseAdapter {

    private Context context;
    private List<ProjectItemData> list;
    private int selectIndex = 0;

    public GvShopSlidingAdapter(Context context, List<ProjectItemData> titles) {
        this.context = context;
        this.list = titles;
    }

    public int getSelectIndex() {
        return selectIndex;
    }

    public void setSelectIndex(int selectIndex) {
        this.selectIndex = selectIndex;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

//    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_sliding_item, parent, false);
            holder.tvText = (TextView) convertView.findViewById(R.id.tvText);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        if(position == selectIndex){

            holder.tvText.setTextColor(context.getResources().getColor(R.color.white));
        }else{

            holder.tvText.setTextColor(context.getResources().getColor(R.color.text_color));
        }
        holder.tvText.setText(list.get(position).getName());
        return convertView;
    }
    class ViewHolder{
        private TextView tvText;
    }
}
